#include <QtGui>
#include <QPalette>
#include <QMessageBox>
#include "digitalclock.h"

DigitalClock::DigitalClock(QWidget *parent, int number): QLCDNumber(parent)
{
    setSegmentStyle(Filled);
    setDigitCount(number);
    this->number=number;

    QTimer *timer = new QTimer(this);
    start_time = QTime::currentTime();

    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));

    this->setObjectName(tr("DIGITAL CLOCK"));

    timer->start(1000);
    showTime();

    QPalette *pp = new QPalette();
    pp->setColor(QPalette::WindowText, Qt::red);
    this->setPalette(*pp);

    this->setFrameStyle(QFrame::NoFrame);

//    resize(parent->width(),parent->height());
    resize(200,50);
}

void DigitalClock::showTime()
{
    QTime time = QTime::currentTime();
    QString text = "";
    if(number == 5)
    {
        text =  time.toString("HH:mm");
    }
    else if(number ==8)
    {
        text =  time.toString("HH:mm:ss");
    }

    //    if (isappear)
    //    {
    //        text[5] = ' ';
    //    }
    //    isappear = !isappear;

    current_time = text;

    int mls = start_time.msecsTo(time);
    QString seconds = QString::number(mls/1000);

    elapsed_time = seconds;
    display(text);
}
